<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <link rel="stylesheet" type="text/css" href="../res/static/css/main.css">
  <link rel="stylesheet" type="text/css" href="../res/layui/css/layui.css">
  <script type="text/javascript" src="../res/layui/layui.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <style type="text/css">
	.layui-input{
		width: 300px;
	}
</style>
</head>
<body>

  <div class="site-nav-bg">
    <div class="site-nav w1200">
      <p class="sn-back-home">
        <i class="layui-icon layui-icon-home"></i>
        <a href="#"><a href=".">首页</a></a>
      </p>
      
      <div class="sn-quick-menu">
        <div class="login"><a href="login.html">登录</a></div>
        <div class="sp-cart"><a href="shopcart.html">购物车</a></div>
        <div class="address"><a href="address.html">个人收货地址</a></div>
        <div class="myorders"><a href="myorders.html">所有订单</a></div>
        <div class="users"><a href="users.html">个人信息</a></div>
      </div>
    </div>
  </div>



  <div class="header">
    <div class="headerLayout w1200">
      <div class="headerCon">
        <h1 class="mallLogo">
          <a href="#" title="潮流男鞋">
            <img src="/file/logo.jpg">
          </a>
        </h1>
        <div class="mallSearch">
          <form action="" class="layui-form" novalidate  lay-filter="user">
            <input type="text" name="title" required  lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入需要的商品">
            <button class="layui-btn" lay-submit lay-filter="formDemo">
                <i class="layui-icon layui-icon-search"></i>
            </button>
            <input type="hidden" name="" value="">
          </form>
        </div>
      </div>
    </div>
  </div>


  <div class="content content-nav-base shopcart-content">
    <div class="main-nav">
      <div class="inner-cont0">
        <div class="inner-cont1 w1200">
          <div class="inner-cont2">
            <a href="commodity.html" class="active">所有商品</a>
            <a href="buytoday.html">今日团购</a>
            <!-- <a href="information.html">母婴资讯</a> -->
            <a href="about.html">关于我们</a>
          </div>
        </div>
      </div>
    </div>
    <form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <!-- 隐藏文本框，存放id -->
	<input type="hidden" id="id" name="id">
  <div class="layui-form-item">
    <label class="layui-form-label">头像</label>
    <div class="layui-input-block">
      <img id="face" style="width: 200px;height: 200px;border: 1px solid lightblue" src="/file/cat.jpg">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">昵称</label>
    <div class="layui-input-inline">
      <input type="text" id="nickname" name="nickname" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">手机号</label>
    <div class="layui-input-inline">
      <input type="text" id="phone" name="phone" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">余额</label>
    <div class="layui-input-inline">
      <input type="text" disabled id="balance" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">默认收货地址</label>
    <div class="layui-input-inline">
      <input type="text"  disabled id="addressId"  placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
  <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</form>

<script>
layui.use(['form','jquery'], function(){
  var form = layui.form;
  var $=layui.jquery;
  //从会话中取出登录用户的信息
  //因为sessionStorage存储的是字符串类型，所以要用JSON.parse的字符串将json字符串转换成json对象
 var user = JSON.parse(sessionStorage.getItem("user"));
  console.log(user)

  $.post(
	 "../users/findById.do?id="+user.id,
	 function(res) {
		//数据回显
		$("#id").val(user.id);
		  $("#face").attr("src",'/file/'+user.face);
		  $("#nickname").val(user.nickname);
		  $("#balance").val(user.balance);
		  $("#phone").val(user.phone);
	},"json"
  
  );
  
  
  //查询用户的默认收货地址
  $.post(
	 "../../address/findAddressById.do?id="+user.addressId,
	 function(res) {
		$("#addressId").val(res.province+res.city+res.detail+" "+res.name+" "+res.phone);
	},"json"
  
  );

  //监听表单提交
  form.on('submit(*)', function(data){
	  console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
	  console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
	  console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
	  $.post(
		"../users/editqin.do",
		data.field,
		function(res) {
			layer.msg("操作成功！")
		}
	  
	  );
	  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
	  
	});
  
});
</script>







  </div>
</body>
</html>